using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class HRM_INSURANCE_MODIFYData : DatabaseObjectBase
	{
		public HRM_INSURANCE_MODIFYData()
		{
			Initialize(true);
		}
		public HRM_INSURANCE_MODIFYData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 HRM_INSURANCE_MODIFY_Insert(Guid ModifyID, Guid InsuranceTableListID, String EmployeeCode, String EmployeeName, String SocialInsuranceCode, String HealthInsuranceCode, String ContentChange, String OldContent, String NewContent, String Reason, String DecideNumber, DateTime DecideDate, String DecidePerson)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("HRM_INSURANCE_MODIFY_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@ModifyID", SqlDbType.UniqueIdentifier));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@InsuranceTableListID", SqlDbType.UniqueIdentifier));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@EmployeeName", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@SocialInsuranceCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@HealthInsuranceCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@ContentChange", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@OldContent", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@NewContent", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DecideDate", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DecidePerson", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Prepare();
				SqlGuid ModifyIDSQL = ModifyID;
				_dbadapter.InsertCommand.Parameters["@ModifyID"].Value = ModifyIDSQL;
				SqlGuid InsuranceTableListIDSQL = InsuranceTableListID;
				_dbadapter.InsertCommand.Parameters["@InsuranceTableListID"].Value = InsuranceTableListIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.InsertCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString EmployeeNameSQL = EmployeeName;
				_dbadapter.InsertCommand.Parameters["@EmployeeName"].Value = EmployeeNameSQL;
				SqlString SocialInsuranceCodeSQL = SocialInsuranceCode;
				_dbadapter.InsertCommand.Parameters["@SocialInsuranceCode"].Value = SocialInsuranceCodeSQL;
				SqlString HealthInsuranceCodeSQL = HealthInsuranceCode;
				_dbadapter.InsertCommand.Parameters["@HealthInsuranceCode"].Value = HealthInsuranceCodeSQL;
				SqlString ContentChangeSQL = ContentChange;
				_dbadapter.InsertCommand.Parameters["@ContentChange"].Value = ContentChangeSQL;
				SqlString OldContentSQL = OldContent;
				_dbadapter.InsertCommand.Parameters["@OldContent"].Value = OldContentSQL;
				SqlString NewContentSQL = NewContent;
				_dbadapter.InsertCommand.Parameters["@NewContent"].Value = NewContentSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.InsertCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.InsertCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlDateTime DecideDateSQL = SqlDateTime.Null;
				if (DecideDate > DateTime.MinValue)
				{
					try
					{
						DecideDateSQL = DecideDate;
					}
					catch (Exception eDecideDate)
					{
						String DecideDateMessage = eDecideDate.Message;
						DecideDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@DecideDate"].Value = DecideDateSQL;
				SqlString DecidePersonSQL = DecidePerson;
				_dbadapter.InsertCommand.Parameters["@DecidePerson"].Value = DecidePersonSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_INSURANCE_MODIFY_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_INSURANCE_MODIFY_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_INSURANCE_MODIFY_Update(Guid ModifyID, Guid InsuranceTableListID, String EmployeeCode, String EmployeeName, String SocialInsuranceCode, String HealthInsuranceCode, String ContentChange, String OldContent, String NewContent, String Reason, String DecideNumber, DateTime DecideDate, String DecidePerson)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_INSURANCE_MODIFY_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ModifyID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@InsuranceTableListID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeName", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SocialInsuranceCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@HealthInsuranceCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ContentChange", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OldContent", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@NewContent", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecidePerson", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid ModifyIDSQL = ModifyID;
				_dbadapter.UpdateCommand.Parameters["@ModifyID"].Value = ModifyIDSQL;
				SqlGuid InsuranceTableListIDSQL = InsuranceTableListID;
				_dbadapter.UpdateCommand.Parameters["@InsuranceTableListID"].Value = InsuranceTableListIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString EmployeeNameSQL = EmployeeName;
				_dbadapter.UpdateCommand.Parameters["@EmployeeName"].Value = EmployeeNameSQL;
				SqlString SocialInsuranceCodeSQL = SocialInsuranceCode;
				_dbadapter.UpdateCommand.Parameters["@SocialInsuranceCode"].Value = SocialInsuranceCodeSQL;
				SqlString HealthInsuranceCodeSQL = HealthInsuranceCode;
				_dbadapter.UpdateCommand.Parameters["@HealthInsuranceCode"].Value = HealthInsuranceCodeSQL;
				SqlString ContentChangeSQL = ContentChange;
				_dbadapter.UpdateCommand.Parameters["@ContentChange"].Value = ContentChangeSQL;
				SqlString OldContentSQL = OldContent;
				_dbadapter.UpdateCommand.Parameters["@OldContent"].Value = OldContentSQL;
				SqlString NewContentSQL = NewContent;
				_dbadapter.UpdateCommand.Parameters["@NewContent"].Value = NewContentSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.UpdateCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.UpdateCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlDateTime DecideDateSQL = SqlDateTime.Null;
				if (DecideDate > DateTime.MinValue)
				{
					try
					{
						DecideDateSQL = DecideDate;
					}
					catch (Exception eDecideDate)
					{
						String DecideDateMessage = eDecideDate.Message;
						DecideDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@DecideDate"].Value = DecideDateSQL;
				SqlString DecidePersonSQL = DecidePerson;
				_dbadapter.UpdateCommand.Parameters["@DecidePerson"].Value = DecidePersonSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_INSURANCE_MODIFY_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_INSURANCE_MODIFY_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_INSURANCE_MODIFY_Disable(Guid ModifyID, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_INSURANCE_MODIFY_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ModifyID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid ModifyIDSQL = ModifyID;
				_dbadapter.UpdateCommand.Parameters["@ModifyID"].Value = ModifyIDSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_INSURANCE_MODIFY_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_INSURANCE_MODIFY_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_INSURANCE_MODIFY_Delete(Guid ModifyID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("HRM_INSURANCE_MODIFY_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@ModifyID", SqlDbType.UniqueIdentifier));
				_dbadapter.DeleteCommand.Prepare();
				SqlGuid ModifyIDSQL = ModifyID;
				_dbadapter.DeleteCommand.Parameters["@ModifyID"].Value = ModifyIDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_INSURANCE_MODIFY_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_INSURANCE_MODIFY_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_INSURANCE_MODIFY_Save(Guid ModifyID, Guid InsuranceTableListID, String EmployeeCode, String EmployeeName, String SocialInsuranceCode, String HealthInsuranceCode, String ContentChange, String OldContent, String NewContent, String Reason, String DecideNumber, DateTime DecideDate, String DecidePerson)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_INSURANCE_MODIFY_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ModifyID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@InsuranceTableListID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeName", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SocialInsuranceCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@HealthInsuranceCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ContentChange", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OldContent", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@NewContent", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecidePerson", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid ModifyIDSQL = ModifyID;
				_dbadapter.UpdateCommand.Parameters["@ModifyID"].Value = ModifyIDSQL;
				SqlGuid InsuranceTableListIDSQL = InsuranceTableListID;
				_dbadapter.UpdateCommand.Parameters["@InsuranceTableListID"].Value = InsuranceTableListIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString EmployeeNameSQL = EmployeeName;
				_dbadapter.UpdateCommand.Parameters["@EmployeeName"].Value = EmployeeNameSQL;
				SqlString SocialInsuranceCodeSQL = SocialInsuranceCode;
				_dbadapter.UpdateCommand.Parameters["@SocialInsuranceCode"].Value = SocialInsuranceCodeSQL;
				SqlString HealthInsuranceCodeSQL = HealthInsuranceCode;
				_dbadapter.UpdateCommand.Parameters["@HealthInsuranceCode"].Value = HealthInsuranceCodeSQL;
				SqlString ContentChangeSQL = ContentChange;
				_dbadapter.UpdateCommand.Parameters["@ContentChange"].Value = ContentChangeSQL;
				SqlString OldContentSQL = OldContent;
				_dbadapter.UpdateCommand.Parameters["@OldContent"].Value = OldContentSQL;
				SqlString NewContentSQL = NewContent;
				_dbadapter.UpdateCommand.Parameters["@NewContent"].Value = NewContentSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.UpdateCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.UpdateCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlDateTime DecideDateSQL = SqlDateTime.Null;
				if (DecideDate > DateTime.MinValue)
				{
					try
					{
						DecideDateSQL = DecideDate;
					}
					catch (Exception eDecideDate)
					{
						String DecideDateMessage = eDecideDate.Message;
						DecideDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@DecideDate"].Value = DecideDateSQL;
				SqlString DecidePersonSQL = DecidePerson;
				_dbadapter.UpdateCommand.Parameters["@DecidePerson"].Value = DecidePersonSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_INSURANCE_MODIFY_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_INSURANCE_MODIFY_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_INSURANCE_MODIFY_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_INSURANCE_MODIFY_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_INSURANCE_MODIFY_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_INSURANCE_MODIFY_Get(Guid ModifyID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_INSURANCE_MODIFY_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@ModifyID", SqlDbType.UniqueIdentifier));
				_dbadapter.SelectCommand.Prepare();
				SqlGuid ModifyIDSQL = ModifyID;
				_dbadapter.SelectCommand.Parameters["@ModifyID"].Value = ModifyIDSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_INSURANCE_MODIFY_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
